package com.yanqu.road.server.cmd.activity.flowerstudy;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FlowerStudyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.flowerstudy.FlowerStudyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_FLOWER_STUDY_SUBMIT_ADVANCE, desc = "提前提交答案")
public class FlowerStudySubmitAdvanceCmd extends AbstractCommand {

    FlowerStudyProto.FlowerStudyExamSubmitAdvanceReq req;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        req = FlowerStudyProto.FlowerStudyExamSubmitAdvanceReq.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(FlowerStudyModule.class).submitAdvance(req);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            FlowerStudyProto.FlowerStudyExamSubmitAdvanceResp.Builder builder = FlowerStudyProto.FlowerStudyExamSubmitAdvanceResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_FLOWER_STUDY_SUBMIT_ADVANCE,builder);
        }
    }
}
